package com.lagou.homework4.no1;

import java.util.List;

/**
 * 添加学生信息
 */
public class AddStudent {

    public static List add(List list, Student student){
        //判断学号是否重复
        for(int i=0;i<list.size();i++){
            Student stu = (Student) list.get(i);
            if(stu.getId()==student.getId()){
//                System.out.println("当前学号重复请重新输入");
                try {
                    throw new StunoException("当前学号已重复，不符合要求!");
                }catch (StunoException e){
                    e.printStackTrace();
                }
                return list;
            }
        }
        if (student.getAge() < 0) {
            try{
                throw new AgeException("您输入的年龄不符合要求！");
            }catch (AgeException e){
                e.printStackTrace();
            }
        }else{
            list.add(student);
        }
        return list;
    }
}
